package com.yc.bos.dao.impl;

import com.yc.bos.dao.IFunctionDao;
import com.yc.bos.dao.base.BaseDaoImpl;
import com.yc.bos.model.Function;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class FunctionDaoImpl extends BaseDaoImpl<Function> implements IFunctionDao {
    @Override
    public List<Function> finListByUserId(String userId) {
        String hql="select distinct f from Function f";
        hql+="left outer join f.roles r";
        hql+="left outer join r.users u";
        hql+="where u.id=?";
        return hibernateTemplate.find(hql,userId);
    }

    @Override
    public List<Function> findMenuByUserId(String id) {
        String hql="select distinct f from Function f";
        hql+="left outer join f.roles r";
        hql+="left outer join r.users u";
        hql+="where u.id =? and f.generatemenu='1' order by f.zindex desc";
        return  hibernateTemplate.find(hql,id);

    }

    @Override
    public List<Function> findAllMenu() {
       String hql="from Function f where f.generatemenu='1' order by f.zindex desc";
        return hibernateTemplate.find(hql);
    }
}
